package com.jingjiu.homeservicesbiz.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jingjiu.homeservicesapi.domain.MessageBoard;
import com.jingjiu.homeservicesbiz.mapper.MessageBoardMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 留言板：记录用户的留言信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-04-16
 */
@Service
public class MessageBoardServiceImpl extends ServiceImpl<MessageBoardMapper, MessageBoard>
{
    @Autowired
    private MessageBoardMapper messageBoardMapper;



    public Page<MessageBoard> selectPage(Page<MessageBoard> page, MessageBoard messageBoard) {
        LambdaQueryWrapper<MessageBoard> queryWrapper = new LambdaQueryWrapper<>();

        // 模糊查询留言内容
        if (StringUtils.isNotBlank(messageBoard.getContent())) {
            queryWrapper.like(MessageBoard::getContent, messageBoard.getContent());
        }

        // 模糊查询留言人
        if (StringUtils.isNotBlank(messageBoard.getAuthorName())) {
            queryWrapper.like(MessageBoard::getAuthorName, messageBoard.getAuthorName());
        }

        // 按创建时间排序（可选）
        queryWrapper.orderByDesc(MessageBoard::getCreatedAt);

        return this.page(page, queryWrapper);
    }

    public MessageBoard selectMessageBoardById(Long id)
    {
        return messageBoardMapper.selectMessageBoardById(id);
    }



    /**
     * 新增留言板：记录用户的留言信息
     * 
     * @param messageBoard 留言板：记录用户的留言信息
     * @return 结果
     */

    public int insertMessageBoard(MessageBoard messageBoard)
    {
        return messageBoardMapper.insertMessageBoard(messageBoard);
    }

    /**
     * 修改留言板：记录用户的留言信息
     * 
     * @param messageBoard 留言板：记录用户的留言信息
     * @return 结果
     */

    public int updateMessageBoard(MessageBoard messageBoard)
    {
        return messageBoardMapper.updateMessageBoard(messageBoard);
    }


    /**
     * 删除留言板：记录用户的留言信息信息
     * 
     * @param id 留言板：记录用户的留言信息主键
     * @return 结果
     */

    public int deleteMessageBoardById(Long id)
    {
        return messageBoardMapper.deleteMessageBoardById(id);
    }
}
